﻿using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace NazTek.Documenter.Ssis.Control.Tasks.PipeSubComponent
{
    internal sealed class DataConversion : Base
    {
        internal DataConversion(IDTSComponentMetaData100 subComponent)
            : base(subComponent, null)
        {
        }
        protected override Operation GetOperation(SsisPipe parent)
        {
            var statement = new StringBuilder();
            var inputs = Metadata.InputCollection[0].InputColumnCollection.OfType<IDTSInputColumn100>().ToArray();
            foreach (IDTSOutputColumn100 outCol in Metadata.OutputCollection[0].OutputColumnCollection)
            {
                var input = inputs.First(
                    c => c.LineageID == outCol.CustomPropertyCollection["SourceInputColumnLineageID"].Value);
                statement.AppendFormat("{0} [{1}] -> {2} [{3}]<br>", input.Name, input.DataType, outCol.Name, outCol.DataType);
            }

            return new Operation
            {
                ConnectionName = "Not Applicable",
                Statement = statement.ToString()
            };
        }
    }
}